package com.gct.controller;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gct.controller.base.BaseController;
import com.gct.domain.Audio;
import com.gct.domain.wrapper.DomainWrapper;
import com.gct.service.AudioService;

/*
 * Radio Hour Page
 */
@RestController
@RequestMapping("/audio")
public class AudioController extends BaseController {
    @Autowired
    private AudioService audioService;

    @RequestMapping(value = "/audios/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public DomainWrapper<Audio> queryAudios(@PathVariable("page") long page) {
        try {
            DomainWrapper<Audio> dmw = new DomainWrapper<Audio>();
            dmw.setData(audioService.getAudios());
            return dmw;
        } catch (Throwable e) {
            return this.<Audio>processException(e);
        }
    }

    @RequestMapping(value = "/audiodetail/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public DomainWrapper<Audio> queryAudioById(@PathVariable("id") long id) {
        try {
            DomainWrapper<Audio> dmw = new DomainWrapper<Audio>();
            List<Audio> audios = new LinkedList<Audio>();
            audios.add(audioService.getAudioById(id));
            dmw.setData(audios);
            return dmw;
        } catch (Throwable e) {
            return this.<Audio>processException(e);
        }
    }

}
